﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MetaNote.Model;
using System.Windows.Forms;
namespace MetaNote
{
    public static class ExtensionHelpers
    {
        /// <summary>
        /// Adds to the dictionary if the key is not in use... replace the item if the key is in use.
        /// </summary>
        /// <typeparam name="Key">The type of the ey.</typeparam>
        /// <typeparam name="Item">The type of the tem.</typeparam>
        /// <param name="that">The that.</param>
        /// <param name="key">The key.</param>
        /// <param name="item">The item.</param>
        public static void AddReplace<Key, Item>(this Dictionary<Key, Item> that, Key key, Item item)
        {
            if (that.ContainsKey(key))
            {
                that[key] = item;
            }
            else
            {
                that.Add(key, item);
            }
        }

        public static MenuItemType ToMenuType(this ToolStripItem toolStripItem)
        {
            if (toolStripItem is ToolStripSeparator)
            {
                return MenuItemType.Separator;
            }

            if (toolStripItem is ToolStripMenuItem)
            {
                return MenuItemType.ToolStripMenu;
            }

            if (toolStripItem is ToolStripButton)
            {
                return MenuItemType.ToolStripButton;
            }

            if (toolStripItem is ToolStripSplitButton)
            {
                return MenuItemType.ToolStripSplitButton;
            }

            return MenuItemType.ToolStripMenu;
        }
    }
}
